<?php
			
	/* SVN FILE: $Id: view.php 17 2011-03-14 22:13:26Z michele.andreoletti@gmail.com $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: michele.andreoletti@gmail.com $
	 * @version $Revision: 17 $
	 * @lastrevision $Date: 2011-03-14 22:13:26 +0000 (Mon, 14 Mar 2011) $
	 * @filesource $URL: http://arcadia.googlecode.com/svn/trunk/fornitori/view.php $
	 */

	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';

	require_once('../include/view.php');

	if (!empty($iView)) {
		$sHeaderTitle = $sAPP_NAME." &raquo; ".$aData['sFornitore']." &raquo; ".$aData['sDescrizione'];
		$sTableTitle = "<div style='font-size: 0.7em'>".$aData['sFornitore']."</div><div>".$aData['sDescrizione']."</div>";
	} else  {
		$sHeaderTitle = $sAPP_NAME." &raquo; $sTableTitle";
	}
	
	$html .= "<div id='tabs'><ul>$sTabsHtml</ul>";

	$i = 1;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {
		
			$html .= "<div id='tabs-$i'>";

			$html .= ($sAction == 'edit' ? "<form method='post' id='form-tab-$i' class='buttons' action='transact.php'>" : '');
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";

				$html .= "<col width='20%'><col width='30%'><col width='50%'>";	
				$html .= "<tbody>";

				$html .= "<tr><td colspan='2'>".fnTextInput('sFornitore','fornitore',$aData,43)."</td>
									<td rowspan='2' style='vertical-align:top; padding-top:8px; padding-left:12px;'>".
										fnCheckboxInput('iControllo',"contratto sottoposto a <strong>Controllo del Fornitore</strong>",$aData)."<br/>
											<div>&nbsp;</div>".
										fnCheckboxInput('iArchivio',"contratto concluso (archivio)",$aData)."<br/>
											<div>&nbsp;</div>".
										fnCheckboxInput('iTrasversale',"contratto trasversale",$aData)."<br/>
											<div>&nbsp;</div>".
									"</td></tr>";
				$html .= "<tr><td colspan='2'>".fnTextareaInput('sDescrizione','oggetto della fornitura',$aData)."</td></tr>";
				$html .= "<tr><td>".fnTextInput('dtAtto','data autorizz.',$aData)."</td><td>".fnTextInput('sAtto','autorizz. (delibera, determina, ordine)',$aData,20)."</td>
								<td rowspan='2'>".
								fnTextareaInput('sUnita','unità interessate',$aData)."</td></tr>";
				$html .= "<tr><td>".fnTextInput('dtScadenza','data scadenza',$aData)."</td><td>".fnSelectInput('iTipo', 'tipologia contratto', $aData, fnSelOptionsFromResources('TIPO-CONTRATTO', '1', 'iTipo'), 'index')."</td></tr>";
				$html .= "<tr><td colspan='2'><br/>".fnTextInput('sRUP','responsabile del procedimento',$aData,43)."</td>
								<td rowspan='2'>".
								fnTextareaInput('sOrdine','ordini collegati',$aData)."</td></tr>";
				$html .= "<tr><td colspan='2'>".fnTextInput('sRupEmail',"e-mail responsabile del procedimento",$aData,43)."</td></tr>";			
				$html .= "<tr><td colspan='2'><br/>".fnTextInput('sDEC',"direttore dell'esecuzione del contratto",$aData,43)."</td>
								<td rowspan='2'>".
								fnTextareaInput('sAppCollegate','apparecchiature collegate',$aData)."</td></tr>";			
				$html .= "<tr><td colspan='2'>".fnTextInput('sDecEmail',"e-mail direttore dell'esecuzione del contratto",$aData,43)."</td></tr>";			
				
				$html .= "</tbody>";
			$html .= "</table>";
				
			$html .= "<br/><hr/>";
				
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";
				$html .= "<col width='25%'><col width='25%'><col width='50%'>";	
				$html .= "<tbody>";
				
				$html .= "<tr><td colspan='2'>".fnTextareaInput('sNote','note',$aData)."</td>
								<td style='vertical-align:top;'>".
								fnTextareaInput('sManutenzione','note sulla manutenzione',$aData)."</td></tr>";	
				$html .= "<tr><td colspan='2'>&nbsp;</td><td>".fnTextareaInput('sManutentore','responsabile manutenzione (nome, tel., email, ...)',$aData)."</td></tr>";
				$html .= "<tr><td colspan='3'>&nbsp;</td></tr>";		
			
				$html .= "</tbody>";
			$html .= "</table>";

			$html .= "<br/>";
			if ($iView != 0) { 
				$html .= (isset($aData['tsCreatedWhen']) && $aData['tsCreatedWhen']!='0000-00-00 00:00:00' ? "<span class='small-text'>".fnHtmlCreatedWhen($aData['tsCreatedWhen'])."</span><br/>" : '');
				$html .= "<span class='small-text'>".fnHtmlLastModify($aData['tsLastModify'])."</span>";
			}
			
			$html .= "<div>&nbsp;</div>";
			$html .= fnButtons($iView, $i, $iAccessLvl, $aData);
			
		$html .= "</div>";
	
	}
	
	$i = 2;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {

		$html .= "<div id='tabs-$i'>";
			$html .= "<table cellpadding='4' cellspacing='0' class='display' border='".fnTableBorder()."' width='98%'>";
				$html .= "	<col width='14%'><col width='14%'>
							<col width='4%'><col width='20%'>
							<col width='4%'><col width='20%'>
							<col width='4%'><col width='20%'>";	
				
				$html .= "<thead>";
				$html .= "<tr>	<th style='border-bottom: 1px solid;'>referente</th>
								<th style='border-bottom: 1px solid;'>data verifica</th>
								<th style='border-bottom: 1px solid;'>esito verifica</th>
								<th style='border-bottom: 1px solid;'>note verifica</th>
								<th style='border-bottom: 1px solid;'>esito sollecito</th>
								<th style='border-bottom: 1px solid;'>note sollecito</th>						
								<th style='border-bottom: 1px solid;'>seguito</th>
								<th style='border-bottom: 1px solid;'>esito finale</th>
									</tr>";
				$html .= "</thead>";
				$sQuery = "SELECT * FROM `el_controlli` WHERE `iContratto`='$iView' AND `iTrash`='0' ORDER BY `dtVerifica` DESC";
				$rResult = custom_mysql_query($sQuery);
				$html .= "<tbody>";
				if (mysql_num_rows($rResult) > 0) {
					while ( $aRow = mysql_fetch_array( $rResult ) ) {
						$sBgcolor = (!isset($sBgcolor) || $sBgcolor == 'F2F2FF' ? 'E2E2F2' : 'F2F2FF');
						$html .= "	<tr bgcolor='#".$sBgcolor."'>	<td><a href='controllo.php?iView=".$aRow['id']."'>".$aRow['sReferenteVerifica']."</a></td>
														<td><a href='controllo.php?iView=".$aRow['id']."'>".date_convert($aRow['dtVerifica'], 'html')."</a></td>";
						
						// 14/03/2011 Le seguenti istruzioni sono state inserite per permettere di avere icone di colore diverso a seconda del tipo di controllo
						$sFlagIcon = fnGetResourceProperties($aRow['iEsitoVerifica'], 'sIconFile', 'ESITO-CONTROLLO');
						if ($sFlagIcon == 'flag_red.png') $sFlagIcon = 'flag_yellow.png';
								
						$html .= "			<td><div class='center'>".(!empty($aRow['iEsitoVerifica']) ? "<img src='../themes/common/images/".$sFlagIcon."' border='0' />" : '')."</div></td>
														<td>".$aRow['sNoteVerifica']."</td>";
						
						// 14/03/2011 Le seguenti istruzioni sono state inserite per permettere di avere icone di colore diverso a seconda del tipo di controllo
						$sFlagIcon = fnGetResourceProperties($aRow['iEsitoSollecito'], 'sIconFile', 'ESITO-CONTROLLO');
						if ($sFlagIcon == 'flag_red.png') $sFlagIcon = 'flag_orange.png';	
						
						$html .= "			<td><div class='center'>".(!empty($aRow['iEsitoSollecito']) ? "<img src='../themes/common/images/".$sFlagIcon."' border='0' />" : '')."</div></td>
														<td>".$aRow['sNoteSollecito']."</td>";
						$html .= "			<td>".$aRow['sSeguito']."</td>
														<td><div class='center'>".(!empty($aRow['iEsitoFinale']) ? "<img src='../themes/common/images/".fnGetResourceProperties($aRow['iEsitoFinale'], 'sIconFile', 'ESITO-CONTROLLO')."' border='0' />" : '')."</div></td>
														
									</tr>";
					}
				} else {
					$html .= "<tr><td colspan='8'><center><em>Nessuna verifica inserita</em></center></td></tr>";
				}
				$html .= "</tbody>";
			$html .= "</table>";
			$html .= "<h5>&nbsp;</h5>";	
		$html .= "</div>";

	}		
		
	$i = 3;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {
		
		$html .= "<div id='tabs-$i'>";
			$html .= ($sAction=='edit' ? "<form method='post' id='form-$i' class='buttons' action='transact.php'>" : "");
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";
			$html .= "<col width='25%'><col width='25%'><col width='25%'><col width='25%'>";	
			$html .= "<tr><td colspan='2'>".fnTextareaInput('sTraslocoReferente',"<strong style='font-size:110%;'>referente</strong><span style='display:block;'>nome, cognome, telefono, fax, email, ...</span>",$aData)."</td>";
				$html .= "<td colspan='2'>".fnTextareaInput('sTraslocoPreavviso',"<strong style='font-size:110%;'>preavviso</strong><span style='display:block;'>tempi di preavviso per attivare l'intervento del Fornitore</span>",$aData)."</td></tr>";
			$html .= "<tr><td colspan='2'>".fnTextareaInput('sTraslocoTempistica',"<strong style='font-size:110%;'>tempistica</strong><span style='display:block;'>tempi <strong>certi</strong> per l'installazione delle apparecchiature da traslocare</span>",$aData)."</td>";
				$html .= "<td colspan='2'>".fnTextareaInput('sTraslocoOsservazioni',"<strong style='font-size:110%;'>osservazioni tecniche</strong><span style='display:block;'>predisposizioni impiantistiche necessarie, da realizzare <strong>prima</strong> del trasloco</span>",$aData)."</td></tr>";
			$html .= "<tr><td colspan='2'>".fnTextareaInput('sTraslocoMuletto',"<strong style='font-size:110%;'>muletto</strong><span style='display:block;'>eventualmente messo a disposizione dal fornitore</span>",$aData)."</td>";
				$html .= "<td colspan='2'>".fnTextareaInput('sTraslocoPersonale',"<strong style='font-size:110%;'>personale</strong><span style='display:block;'>eventualmente messo a disposizione dal Fornitore</span>",$aData)."</td></tr>";
			$html .= "<tr><td colspan='2'>".fnTextareaInput('sTraslocoTraslocatore',"<strong style='font-size:110%;'>traslocatore</strong><span style='display:block;'>indicare <strong>chi</strong> effettuerà il trasloco (fornitore, azienda ospedaliera, ...)</span>",$aData)."</td>";
				$html .= "<td colspan='2'>".fnTextareaInput('sTraslocoCosti',"<strong style='font-size:110%;'>costi</strong><span style='display:block;'>costi per lavori/trasloco, da indicare se a carico dell'azienda ospedaliera</span>",$aData)."</td></tr>";
			$html .= "<tr><td colspan='2'>".fnTextareaInput('sTraslocoSopralluogo',"<strong style='font-size:110%;'>soprallugo</strong><span style='display:block;'>indicare se è necessario un sopralluogo prima del trasloco</span>",$aData)."</td></tr>";
			$html .= "<tr><td colspan='4'>&nbsp;</td></tr>";	
			$html .= "</table>";
			$html .= "<h5>&nbsp;</h5>";	
			$html .= fnButtons($iView, $i, $iAccessLvl, $aData);
		$html .= "</div>";

	}		
	
	$i = $iTabUploads;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $sViewItemLink, $i))) { 
		
		$html .= "<div id='tabs-$i'>";			
			$html .= fnUploadsTabContent($iView, $sViewItemLink, $i);
		$html .= "</div>";
	
	}
			
	$html .= "</div>";
				
	// contenuto <head> della pagine
	$sHeadContent .= fnViewHeadContent($iTab, $aDisabledTabs);
		
	$bSEARCH_FORM_SHOW = false; // il form di ricerca non viene visualizzato nello script $sViewItemLink
								// non posso assegnare subito questo valore a $bSEARCH_FORM_SHOW perchè
								// alcune funzioni in ../include/view.php utilizzano questa variabile.
								
	require_once('../themes/'.$sTHEME.'/template.php');
	die();




	function fnViewHeadContent ($iTab, $aTabsDisabled) {

		global $sSUITE_NAME, $sAPP;
		
		global $iView, $sViewItemLink;
		
		global $sAction;
		
		global $sJsDocumentReady;
		
		global $aTabsLabels;
		
		$sTabsDisabled = '';
		foreach ($aTabsDisabled as $i) { $sTabsDisabled .= "$i, "; }
		$sTabsDisabled = ($sTabsDisabled!='' ? " disabled: [".substr_replace( $sTabsDisabled, "", -2 )."] " : '');

		$iTabSelected = $i = 0;
		foreach ($aTabsLabels as $sKey => $sValue) {
			if ($sKey == $iTab) { $iTabSelected = $i; }
			$i++;
		}
		
		$sSelectedTab = ($iTabSelected!=0 && !in_array($iTabSelected, $aTabsDisabled) ? ($sTabsDisabled!="" ? ", " : '') . " selected: $iTabSelected " : "");

		$sHeadContent = "

			<script type='text/javascript' charset='utf-8'>
	
				$().ready(function() {
					
					$sJsDocumentReady
					
					$('#tabs').tabs({ $sTabsDisabled $sSelectedTab });
				
					$('button, input:submit', '.buttons').button();
					
					$('.ui-toggable').click(function() {
						src = $(this).attr('src'),
							onCheck = /\_on\.png$/,
							offCheck = /\_off\.png$/;
						fnToggle($(this));
					});
					
					function fnToggle (oObj) {
						oCliked = null;
						src = oObj.attr('src'),
							onCheck = /\_on\.png$/,
							offCheck = /\_off\.png$/;
						$.getJSON('../include/toggle.php', {'sAction': 'toggle',
															'sField': oObj.attr('sField'),
															'sValue': (src.match(onCheck) ? 0 : 1),
															'iView': '$iView',
															'sTable': '',
															'sViewItemLink': '$sViewItemLink',
															'sAPP': '$sAPP'	}, function (json) {
							if (json[0].sAction=='toggle' && json[0].sError=='') { 
								if(src.match(onCheck)) {
									oObj.attr('src', src.replace(onCheck, '_off.png'));
								} else if (src.match(offCheck)) {
									oObj.attr('src', src.replace(offCheck, '_on.png'));
								}
							} else { 
								alert ('Error: ' + json[0].sError);
							} 		
						})
					}; " . ($sAction == 'edit' ? "
									
					$('#sFornitore').autocomplete({
						source: 'fornitore_suggestions.php',
						minLength: 2,
						select: function(event, ui) {
							$(this).val(ui.item.value);
						}
					}); " : '') . "
					
				});
				</script> ";
	
		return $sHeadContent;
	}

?>